<!DOCTYPE html>
<html lang="zh-CN"
      xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>搜索</title>
    <meta name="keywords" content="搜索" />
    <meta name="description" content="搜索" />
    <meta name="viewport" content="width=device-width,initial-scale=1, maximum-scale=1,minimum-scale=1, user-scalable=no">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="format-detection" content="telephone=no" />
    <meta name="viewport" content="width=device-width,viewport-fit=cover">
    <link rel="stylesheet" type="text/css" th:href="@{/shoppingApi/css/public.css}">
    <link rel="stylesheet" type="text/css" th:href="@{/shoppingApi/css/swiper.min.css}">
    <link rel="stylesheet" type="text/css" th:href="@{/shoppingApi/css/search.css}">
    <style type="text/css" rel="stylesheet">
        .searchpage .close {
            width: 25px;
            top: 10px;
            z-index: 5;
            right: 67px;

        }
        .close-search{
            display: none;
        }
    </style>
</head>
<body>
<div class="main searchpage">
    <div class="main_con">
        <div class="bgfff pl15 pr15 search">
            <div class="search_con flex flex-ac">
                <img class="back" th:src="@{/shoppingApi/images/back.png}">
                <div class="it1 ml10 mr10 bround20">
                    <div class="flex flex-ac">
                        <img  class="searchimg ml15" th:src="@{/shoppingApi/images/search.png}">
                        <input class="it1" id="search" type="search" name="it1" value="" placeholder="请输入关键词">
                        <img class="close abs close-search" th:src="@{/shoppingApi/images/close.png}">
                    </div>
                </div>
                <span class="ft15 c323232 searchbtn">搜索</span>
            </div>
        </div>
        <div class="pt15 bgfff c323232 ft12 rela" id="search-history">
            <p class="ft17 c323232 pl15 pr15 pb10" >最近搜索</p>
            <ul class="overflow  search-his-li"  >
                <li>茶多酚</li>
                <!--<li>传奇天露</li>-->
                <!--<li>测试1</li>-->
                <!--<li>测试测试3</li>-->
                <!--<li>测试4</li>-->
                <!--<li>测试4</li>-->
                <!--<li>测试5</li>-->
                <!--<li>测试5</li>-->
                <!--<li>测试5</li>-->
                <!--<li>测试5</li>-->
            </ul>
            <img class="close abs  clear-search" th:src="@{/shoppingApi/images/close1.png}">
        </div>
    </div>
</div>
</body>
<script type="text/javascript" th:src="@{/shoppingApi/js/jquery-3.3.1.min.js}"></script>
<script type="application/javascript" th:src="@{/shoppingApi/js/common.js}"></script>
<script type="application/javascript">
    $(".searchpage ul li").on('click',function () {
       var productName= $(this).text();
           // alert($(this).text());
        // window.location.href='/wap/searchResult'
        window.location.href='/wap/searchResult?productName='+productName
    })
    $(".searchpage .close").on('click',function () {
        // alert("清除搜索");
        // $(".it1").val("");

    })

    // 手机软键盘“搜索”
    $("#search").on('keypress',function(e) {
        var keycode = e.keyCode;
        var productName = $(this).val();
        if(keycode=='13') {
            window.location.href='/wap/searchResult?productName='+productName;
            e.preventDefault();
        }
    });

    $(".search .search_con .searchbtn").on('click',function () {
        var productName = $(this).parents(".search").find("input").val();
        // alert(productName);
        //alert(productName);
        window.location.href='/wap/searchResult?productName='+productName;
        // $.ajax({
        //     url:'/wap/addSearchHistory?productName='+productName,
        //     success:function (result) {
        //         console.log(result);
        //     }
        // })
    })
    $(".back").on('click',function () {
        window.history.back(-1);
    })

    $(".it1").on('keyup',function () {
        var value=$(".it1").val();

        if(value=""){
            // alert("v="+value);
        }else{
            $(".close-search").css({'display':'block'});
        }
        // alert("清除搜索");

    })
    $(".close-search").on('click',function () {
        $(".it1").val("");
        // $(".overflow li").html("");

    })
    $(".clear-search").on('click',function () {
        $.ajax({
            url:'/wap/deleteSearchHistoryByUserId',
            success:function (result) {
                console.log(result);
            }
        })
        $(".overflow li").html("");
        $(".overflow li").remove();
    })

$(function () {
    $.ajax({
        url:'/wap/selectSearchHistoryByUserId',
        success:function (result) {
           var data=result.searchHistoryList;
           $.each(data,function (i) {
               if(data[i].shContent!=null&&data[i].shContent!=""){
                   $('.overflow').append("<li>"+data[i].shContent+"</li>");
               }
           })
        }
    })


})

    /*点击搜索历史记录*/
    $(document).on('click','li',function (){
       var productName= $(this).html();
        if(productName!=null&&productName!=""){
            window.location.href='/wap/searchResult?productName='+productName;
        }
    })
</script>
</html>